#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
const ll N = 2e5 + 10;
ll head=-1, e[N], ne[N],idx;
char c;
ll k, x;
void init()
{
    head = -1;
    idx = 0;
}
void add_to_head(int x)
{
    e[idx] = x;
    ne[idx] = head;
    head = idx;
    
    idx++;
}
void add(int k,int x)
{
    e[idx] = x;
    ne[idx] = ne[k];
    ne[k] = idx;
    
    idx++;
}
void remove(int k)
{
    ne[k] = ne[ne[k]];
}
void solve()
{

    cin >> c;
    if(c=='H'){
        cin >> x;
        add_to_head(x);
    }
    else if(c=='D')
    {
        ll k;
        cin >> k;
        if(!k)
            head = ne[head];
        remove(k-1);
    }
    else {
        cin >> k >> x;
        add(k-1, x);
    }


}
int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    for (ll i = head; i != -1; i = ne[i])
    {
        cout << e[i] << " ";
    }
   return 0;
}
